package org.example.filter;

import io.jsonwebtoken.Claims;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.example.web.JwtUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

@Configuration
public class JwtAuthenticationFilter extends OncePerRequestFilter{
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        String token = request.getHeader("token");
        if(token==null||token.equals("")){
            filterChain.doFilter(request,response);
            return;
        }

    }











//    @Override
//    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
//        String token = request.getHeader("token");
//        if(token==null){
//            doFilter(request,response,filterChain);
//            return;
//        }
//        try {
//            JwtUtils.parseToken(token);
//        } catch (Exception e) {
//            response.setStatus(401);
//            throw  new AccessDeniedException("凭证已过期，请重新登录");
//        }
//        doFilter(request,response,filterChain);
//    }
}
